package com.atguigu.spring.aop;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

/**
 * @author 003851 HUANGQING
 * @date 2022/9/19 16:35
 */
@Component
public class AsyncAnnotationExample {

	@Async
	public CompletableFuture<String> doSomething() {
		//  1.创建future
		CompletableFuture<String> result = new CompletableFuture<String>();
		// 2. 模拟任务执行
		try {
			Thread.sleep(1000);
			System.out.println(Thread.currentThread().getName() + "doSomething");
		} catch (Exception e) {
			e.printStackTrace();
		}
		result.complete("done ");
		//3. 返回结果
		return result;
	}
}
